package com.example.whac_a_mole;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Activity_submit extends AppCompatActivity {
private EditText edit_user;
private EditText edit_passwd;
private EditText edit_passwd2;
private Button button_sub;
private Button button_rturn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_submit);
        setTitle("打地鼠-注册新用户");
        edit_user=findViewById(R.id.edit_1);
        edit_passwd=findViewById(R.id.edit_2);
        edit_passwd2=findViewById(R.id.edit_3);
        button_sub=findViewById(R.id.button_submit_1);
        button_rturn=findViewById(R.id.button_submit_2);
        button_sub.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String user=edit_user.getText().toString().trim();
                String passwd1=edit_passwd.getText().toString().trim();
                String passwd2=edit_passwd2.getText().toString().trim();
                if(user.equals("")||passwd1.equals("")||passwd2.equals(""))
                {
                    Toast.makeText(Activity_submit.this,"账号或者密码不能为空,请检查后重新注册!",Toast.LENGTH_LONG).show();
                }
                else
                {
                    if(!passwd1.equals(passwd2))
                    {
                        Toast.makeText(Activity_submit.this,"两次密码输入不一致,请检查后重新注册!",Toast.LENGTH_LONG).show();
                    }
                    else
                    {
                        new DataBase(Activity_submit.this).submit(user,passwd1);
                        Toast.makeText(Activity_submit.this,"注册成功!",Toast.LENGTH_LONG).show();

                    }
                }

            }
        });
        button_rturn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(Activity_submit.this,Activity_login.class));
            }
        });
    }
}
